package com.ljx.thread.thread03;

/**
 * @author LJX
 * @Description: TODO
 * @Date: 2022/11/1 14:40
 * @Version 1.0
 */
public class InterruptThreadTest {
	public static void main(String[] args) {
		InterruptThread interruptThread = new InterruptThread();
		Thread thread = new Thread(interruptThread);
		thread.start();

		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		interruptThread.run=false;
	}
}

class InterruptThread implements Runnable{
	boolean run=true;
	@Override
	public void run() {

			for (int i = 0; i < 10; i++) {
				if(run){
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
					System.out.println(Thread.currentThread().getName()+"----->"+i);
				}else {
					return;
				}
		}

	}
}
